//
//  XZMachineModeDetailCell.m
//  Teecloud
//
//  Created by PC on 2018/11/22.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZMachineModeDetailCell.h"
#import "XZTimeInfo.h"

@interface XZMachineModeDetailCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
/***signIn**/
@property (weak, nonatomic) IBOutlet UIView *signInView;
@property (weak, nonatomic) IBOutlet UILabel *signLabel;
@property (weak, nonatomic) IBOutlet UILabel *signInClockTimeLabel;
@property (weak, nonatomic) IBOutlet UIButton *signInClockStatusButton;
@property (weak, nonatomic) IBOutlet UIButton *signInStatusNamebutton;
@property (weak, nonatomic) IBOutlet UILabel *signInAddressLabel;
/***signOut**/
@property (weak, nonatomic) IBOutlet UILabel *signOutLabel;
@property (weak, nonatomic) IBOutlet UILabel *signOutTimeLabel;
@property (weak, nonatomic) IBOutlet UIButton *signOutStatusButton;
@property (weak, nonatomic) IBOutlet UIButton *signOutStatusNameButton;
@property (weak, nonatomic) IBOutlet UILabel *signOutAddressLabel;
/**View的高度**/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signInViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signOutViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signInViewTop;

/**SignIn的时间 第一个按钮 二个按钮的宽的约束及第二个按钮的b左边距***/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signInWidthOne;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signInWidthTwo;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signInWidthThree;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signInLeftOne;
/**SignOut的时间 第一个按钮 二个按钮的宽的约束及第二个按钮的b左边距***/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signOutWidthOne;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signOutWidthTwo;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signOutWidthThree;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *signOutLeftOne;

@end

@implementation XZMachineModeDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(XZTimeInfo *)model{
    _model = model;
    self.nameLabel.text = model.Name;
    [self.headImg yy_setImageWithURL:[NSURL URLWithString:model.HeadUrl] placeholder:DefealtImg];
    //当签到为false时 签到栏要下移到签退栏
    if (!model.IsNeedSignOut) {
        self.signInViewTop.constant = 24.f;
    }else{
         self.signInViewTop.constant = 0.f;
    }
/**************************SignIn*****************************/
    
    if (!model.IsNeedSignIn) {
        self.signInViewHeight.constant=0.f;
        self.signLabel.hidden = true;
        self.signInClockTimeLabel.hidden = true;
        self.signInClockStatusButton.hidden = true;
        self.signInStatusNamebutton.hidden = true;
        self.signInAddressLabel.hidden = true;
    }else{
        self.signLabel.hidden = false;
        self.signInClockTimeLabel.hidden = false;
        self.signInClockStatusButton.hidden = false;
        self.signInStatusNamebutton.hidden = false;
        self.signInAddressLabel.hidden = false;
        
        if (model.TimeData1.ClockTime != nil) {
            self.signInClockTimeLabel.text = model.TimeData1.ClockTime;
            self.signInWidthOne.constant = 40.f;
        }else{
            self.signInWidthOne.constant = 0.f;
            self.signInClockTimeLabel.hidden = true;
        }
        //第一个按钮
        if (model.TimeData1.ClockStatusName != nil) {
            if ([model.TimeData1.ClockStatusName isEqualToString:@"正常"]) {
                self.signInClockStatusButton.backgroundColor = kWhiteColor;
                [self.signInClockStatusButton setTitleColor:kBlueColor forState:UIControlStateNormal];
                self.signInClockStatusButton.layer.borderWidth = 0.5f;
                self.signInClockStatusButton.layer.borderColor = kBlueColor.CGColor;
            }else if ([model.TimeData1.ClockStatusName isEqualToString:@"迟到"] || [model.TimeData1.ClockStatusName isEqualToString:@"早退"]){
                self.signInClockStatusButton.backgroundColor = kWhiteColor;
                [self.signInClockStatusButton setTitleColor:kFF8700Color forState:UIControlStateNormal];
                self.signInClockStatusButton.layer.borderWidth = 0.5f;
                self.signInClockStatusButton.layer.borderColor = kFF8700Color.CGColor;
            }else if ([model.TimeData1.ClockStatusName isEqualToString:@"缺卡"]){
                self.signInClockStatusButton.backgroundColor = kWhiteColor;
                [self.signInClockStatusButton setTitleColor:kRedColor forState:UIControlStateNormal];
                self.signInClockStatusButton.layer.borderWidth = 0.5f;
                self.signInClockStatusButton.layer.borderColor = kRedColor.CGColor;
            }else if ([model.TimeData1.ClockStatusName isEqualToString:@"请假"]){
                self.signInClockStatusButton.backgroundColor = kFF8700Color;
                [self.signInClockStatusButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
            }
            [self.signInClockStatusButton setTitle:model.TimeData1.ClockStatusName forState:UIControlStateNormal];
            self.signInWidthTwo.constant = 30.f;
        }else{
            self.signInWidthTwo.constant = 0.f;
            self.signInClockStatusButton.hidden = true;
        }
        
        //第二个按钮
        if (model.TimeData1.NamingStatusName != nil) {
            [self.signInStatusNamebutton setTitle:model.TimeData1.NamingStatusName forState:UIControlStateNormal];
            self.signInWidthThree.constant = 30.f;
            if ([model.TimeData1.NamingStatusName isEqualToString:@"已到"]) {
                self.signInStatusNamebutton.backgroundColor = kWhiteColor;
                [self.signInStatusNamebutton setTitleColor:kBlueColor forState:UIControlStateNormal];
                self.signInStatusNamebutton.layer.borderWidth = 0.5f;
                self.signInStatusNamebutton.layer.borderColor = kBlueColor.CGColor;
            }else if ([model.TimeData1.NamingStatusName isEqualToString:@"未到"]){
                self.signInStatusNamebutton.backgroundColor = kWhiteColor;
                [self.signInStatusNamebutton setTitleColor:kRedColor forState:UIControlStateNormal];
                self.signInStatusNamebutton.layer.borderWidth = 0.5f;
                self.signInStatusNamebutton.layer.borderColor = kRedColor.CGColor;
            }else if ([model.TimeData1.NamingStatusName isEqualToString:@"请假"]){
                self.signInStatusNamebutton.backgroundColor = kWhiteColor;
                [self.signInStatusNamebutton setTitleColor:kFF8700Color forState:UIControlStateNormal];
                self.signInStatusNamebutton.layer.borderWidth = 0.5f;
                self.signInStatusNamebutton.layer.borderColor = kFF8700Color.CGColor;
            }
            //如第一个按钮也没有的话就直接设置第二个按钮距离第一个按钮的左边距为0
            if (self.signInWidthTwo.constant == 0) {
                self.signInLeftOne.constant = 0.f;
            }else{
                self.signInLeftOne.constant = 5.f;
            }
        }else{
            self.signInWidthThree.constant = 0.f;
            self.signInStatusNamebutton.hidden = true;
        }
        
        if (model.TimeData1.ClockAddress != nil) {
            self.signInAddressLabel.text = model.TimeData1.ClockAddress;
        }else{
            self.signInAddressLabel.hidden = true;
        }
        self.signInViewHeight.constant=25.f;
    }
    /**************************SignOut*****************************/
    if (!model.IsNeedSignOut) {
        self.signOutViewHeight.constant=0.f;
        self.signOutLabel.hidden = true;
        self.signOutStatusButton.hidden = true;
        self.signOutAddressLabel.hidden = true;
        self.signOutTimeLabel.hidden = true;
        self.signOutStatusNameButton.hidden = true;
    }else{
        self.signOutLabel.hidden = false;
        self.signOutStatusButton.hidden = false;
        self.signOutAddressLabel.hidden = false;
        self.signOutTimeLabel.hidden = false;
        self.signOutStatusNameButton.hidden = false;
        self.signOutViewHeight.constant=25.f;
        
        if (model.TimeData2.ClockTime != nil) {
            self.signOutTimeLabel.text = model.TimeData2.ClockTime;
            self.signOutWidthOne.constant = 40.f;
        }else{
            self.signOutWidthOne.constant = 0.f;
            self.signOutTimeLabel.hidden = true;
        }
        //第一个按钮
        if (model.TimeData2.ClockStatusName != nil) {
            if ([model.TimeData2.ClockStatusName isEqualToString:@"正常"]) {
                self.signOutStatusButton.backgroundColor = kWhiteColor;
                [self.signOutStatusButton setTitleColor:kBlueColor forState:UIControlStateNormal];
                self.signOutStatusButton.layer.borderWidth = 0.5f;
                self.signOutStatusButton.layer.borderColor = kBlueColor.CGColor;
            }else if ([model.TimeData2.ClockStatusName isEqualToString:@"迟到"] || [model.TimeData2.ClockStatusName isEqualToString:@"早退"]){
                self.signOutStatusButton.backgroundColor = kWhiteColor;
                [self.signOutStatusButton setTitleColor:kFF8700Color forState:UIControlStateNormal];
                self.signOutStatusButton.layer.borderWidth = 0.5f;
                self.signOutStatusButton.layer.borderColor = kFF8700Color.CGColor;
            }else if ([model.TimeData2.ClockStatusName isEqualToString:@"缺卡"]){
                self.signOutStatusButton.backgroundColor = kWhiteColor;
                [self.signOutStatusButton setTitleColor:kRedColor forState:UIControlStateNormal];
                self.signOutStatusButton.layer.borderWidth = 0.5f;
                self.signOutStatusButton.layer.borderColor = kRedColor.CGColor;
            }else if ([model.TimeData2.ClockStatusName isEqualToString:@"请假"]){
                self.signOutStatusButton.backgroundColor = kFF8700Color;
                [self.signOutStatusButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
            }
            [self.signOutStatusButton setTitle:model.TimeData2.ClockStatusName forState:UIControlStateNormal];
            self.signOutWidthTwo.constant = 30.f;
        }else{
            self.signOutWidthTwo.constant = 0.f;
            self.signOutStatusButton.hidden = true;
        }
        
        //第二个按钮
        if (model.TimeData2.NamingStatusName != nil) {
            [self.signOutStatusNameButton setTitle:model.TimeData2.NamingStatusName forState:UIControlStateNormal];
            self.signOutWidthThree.constant = 30.f;
            
            if ([model.TimeData2.NamingStatusName isEqualToString:@"已到"]) {
                self.signOutStatusNameButton.backgroundColor = kWhiteColor;
                [self.signOutStatusNameButton setTitleColor:kBlueColor forState:UIControlStateNormal];
                self.signOutStatusNameButton.layer.borderWidth = 0.5f;
                self.signOutStatusNameButton.layer.borderColor = kBlueColor.CGColor;
            }else if ([model.TimeData2.NamingStatusName isEqualToString:@"未到"]){
                self.signOutStatusNameButton.backgroundColor = kWhiteColor;
                [self.signOutStatusNameButton setTitleColor:kRedColor forState:UIControlStateNormal];
                self.signOutStatusNameButton.layer.borderWidth = 0.5f;
                self.signOutStatusNameButton.layer.borderColor = kRedColor.CGColor;
            }else if ([model.TimeData2.NamingStatusName isEqualToString:@"请假"]){
                self.signOutStatusNameButton.backgroundColor = kWhiteColor;
                [self.signOutStatusNameButton setTitleColor:kFF8700Color forState:UIControlStateNormal];
                self.signOutStatusNameButton.layer.borderWidth = 0.5f;
                self.signOutStatusNameButton.layer.borderColor = kFF8700Color.CGColor;
            }
            //如第一个按钮也没有的话就直接设置第二个按钮距离第一个按钮的左边距为0
            if (self.signOutWidthTwo.constant == 0) {
                self.signOutLeftOne.constant = 0.f;
            }else{
                self.signOutLeftOne.constant = 5.f;
            }
        }else{
            self.signOutWidthThree.constant = 0.f;
            self.signOutStatusNameButton.hidden = true;
        }
        
        if (model.TimeData2.ClockAddress != nil) {
            self.signOutAddressLabel.text = model.TimeData2.ClockAddress;
        }else{
            self.signOutAddressLabel.hidden = true;
        }
    }
}

//签到第一个按钮 如是请假就回调
- (IBAction)signInOneBtnActon:(UIButton *)sender {
    NSString *text = sender.titleLabel.text;
    if ([text isEqualToString:@"请假"]) {
        if (self.leaveBlock) {
            self.leaveBlock(self.model.TimeData1.LeaveApplyId);
        }
    }
}
//签退第一个按钮 如是请假就回调
- (IBAction)signOutOneBtnAction:(UIButton *)sender {
    NSString *text = sender.titleLabel.text;
    if ([text isEqualToString:@"请假"]) {
        if (self.leaveBlock) {
            self.leaveBlock(self.model.TimeData2.LeaveApplyId);
        }
    }
}


@end
